﻿using AutoMapper;
using AutoMapper.Extensions.EnumMapping;
using Core.Utility;
using Dto.Core;
using Entity.Core;

namespace Mapper.Core
{
    /// <summary>
    /// 类库Mapper映射，通常用于Lib公共映射设置
    /// </summary>
    public class LibMapperProfile : Profile
    {

        /// <summary>
        /// 默认构造
        /// </summary>
        public LibMapperProfile()
        {            
            //Dto与Model 数据库类型 映射枚举值
            //CreateMap<Entity.Lib.Enum.DatabaseTypeEnum, Dto.Lib.Enum.DatabaseTypeEnum>()
            //    .ConvertUsingEnumMapping(opt => opt
            //    .MapByValue());

            //Dto与Model模式 映射枚举值
            CreateMap<EntityMode, DtoMode>()
                .ConvertUsingEnumMapping(opt => opt
                .MapByValue())
                .ReverseMap();

            CreateMap<BaseEntity, BaseDto>().IncludeAllDerived()
                .ReverseMap();

            CreateMap<CommonBaseEntity, CommonBaseDto>().IncludeAllDerived()
                .ReverseMap();

            CreateMap<BaseSipEntity, BaseSipDto>().IncludeAllDerived()
                .ReverseMap();

            CreateMap<BaseSopEntity, BaseSopDto>().IncludeAllDerived()
                .ReverseMap();        
            
            CreateMap(typeof(ReturnResultInfo),typeof(ReturnResultInfo<>))
                .ForMember("Data", opt => opt.MapFrom("Data"))
                .ReverseMap();

            CreateMap(typeof(ReturnResultInfo<>), typeof(ReturnResultInfo<>))
            .ForMember("Data", opt => opt.MapFrom("Data"));

        }
    }
}